package com.cskaoyan.gateway.controller.shopping;

import com.cskaoyan.gateway.form.shopping.RealRecommendResponse;
import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.shopping.PanelDetailService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.dto.GoodRecommendResponse;
import com.mall.user.annotation.Anoymous;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: lin
 * @Date: 2020/7/10 19:49
 */

@RestController
@RequestMapping("shopping")
@Anoymous
public class PanelDetailController {

    @Reference(check = false)
    PanelDetailService panelDetailService;


    @GetMapping("recommend")
    public ResponseData recommendHandler(){
        GoodRecommendResponse response = panelDetailService.getPanelDetail();

        if (response.getCode().equals(ShoppingRetCode.SUCCESS.getCode())){
            RealRecommendResponse realResponse = new RealRecommendResponse(
                    response.getId(),
                    response.getName(),
                    response.getType(),
                    response.getSortOrder(),
                    response.getPosition(),
                    response.getLimitNum(),
                    response.getStatus(),
                    response.getRemark(),
                    response.getPanelContentItems()
            );
            List<RealRecommendResponse> list = new ArrayList<>();
            list.add(realResponse);
            return new ResponseUtil().setData(list);
        }
        return new ResponseUtil().setErrorMsg(response.getMsg());
    }

}
